<%@page import="java.util.LinkedList"%>
<%@page import="BusinessLogic.UserContainer"%>
<%@page import="BusinessLogic.Result.ResultType"%>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="BusinessLogic.Result" %>
<%@ page import="BusinessLogic.User" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <jsp:useBean id="requestHandler" class="RequestHandlerPackage.RequestHandler" scope="application"/>
    <%
		Map<String,String[]> params = new HashMap<String,String[]>();
		params.put("action", new String[]{"getAllUsers"});
		Result res = requestHandler.handle(params);
		Map<String,Integer> userCount = new HashMap<String,Integer>();
		String delete = "";
		if (res.getResultType().equals(ResultType.SUCCESS))
		{
			UserContainer cont = (UserContainer)res.getSuccessReturnValue();
			List<User>  users = cont.getAllUsersIn(request.getParameter("letter"));
			String uName = request.getUserPrincipal().getName();
			params.clear();
			params.put("action",new String[]{"getUser"});
			params.put("USER_NAME",new String[]{uName});
			params.put("me",new String[]{uName});
			res = requestHandler.handle(params);
			if (res.getResultType().equals(ResultType.SUCCESS))
			{
				if (((User)(res.getSuccessReturnValue())).getRole().equals("admin")){
				  	delete="<button type=\"button\" onclick=\"deleteUser('*','"+((User)(res.getSuccessReturnValue())).getName()+"')\">Delete User</button>";
				}
			}
			for (User user : users)
			{
				String username = user.getName();
				%>	
							<div id=<%="div"+username %>>
							<table>
							<tr>
							<td>
								<h4 onclick="showCourseDetails('<%=username %>')"><%=username%></h4>
							</td>
							<td><br/>
							<%if (!user.getRole().equals("admin")) {%>
								<%=delete.replace("*",username)%>
								<%} %>
							</td>
							</tr>
							</table>
								<div class="adminkey" id="<%=username%>">
									<p><span class="red">Full Name:</span> <%=user.getFirst_name() +" " + user.getLast_name()%></p>
									<p><span class="red">Email:</span> <%=user.getEmail()%></p>
									<p><span class="red">Phone:</span> <%=user.getPhone()%></p>
									<p><span class="red">Role:</span> <%=user.getRole()%></p>
								</div>
							</div>
						<%
			}
		}
		%>